<?php

switch ($act) {
    case 'wx_login':

        $url = "http://www.ktxwxgy.com/hotel.php?mod=login&act=wx_login";
        $result = pe_wx($url);
        $openid =  $result->openid;
        $nickname =  $result->nickname;
        $user_img =  $result->headimgurl;
        $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
        $page = $_SESSION['page'];
        if(!empty($wxuser)){
            if($wxuser['user_wxname']!=$nickname){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_wxname'=>$nickname));
            }
            if($wxuser['user_headimg']!=$user_img){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_headimg'=>$user_img));
            }
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_vipcard_number'] = $wxuser['user_vipcard_number'];
            $_SESSION['user_moneycard_number'] = $wxuser['user_moneycard_number'];
            $_SESSION['user_wxname'] = $nickname;
            $_SESSION['user_headimg'] = $user_img;
            $_SESSION['user_wxid'] = $openid;
            if($wxuser['user_state']==0){
                pe_goto('hotel.php?mod=index&act=except');
            }else if($page=="personal_center"){
                pe_goto('hotel.php?mod=personal_center');
            }else{
                pe_goto('hotel.php?mod=index');
            }


        }else{

            $user = $db->pe_insert('user', array('user_wxid'=>$openid,'user_wxname'=>$nickname,'user_headimg'=>$user_img));
            $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_vipcard_number'] = $wxuser['user_vipcard_number'];
            $_SESSION['user_moneycard_number'] = $wxuser['user_moneycard_number'];
            $_SESSION['user_wxname'] = $nickname;
            $_SESSION['user_headimg'] = $user_img;
            $_SESSION['user_wxid'] = $openid;
            if($wxuser['user_state']==0){
                pe_goto('hotel.php?mod=index&act=except');
            }else if($page=="personal_center"){
                pe_goto('hotel.php?mod=personal_center');
            }else{
                pe_goto('hotel.php?mod=index');
            }

        }


        break;

    case 'wx_login_recourse':
        $url = "http://ningjianshen.com/njs.php?mod=login&act=wx_login_recourse";
        $result = pe_wx($url);

        $openid =  $result->openid;
        $nickname =  $result->nickname;
        $user_img =  $result->headimgurl;

        $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
        if(!empty($wxuser)){
            if($wxuser['user_wxname']!=$nickname){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_name'=>$nickname));
            }
            if($wxuser['user_img']!=$user_img){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_img'=>$user_img));
            }
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=regular_course');
        }else{

            $user = $db->pe_insert('user', array('user_wxid'=>$openid,'user_wxname'=>$nickname,'user_img'=>$user_img,'user_join_time'=>time()));
            $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=regular_course');
        }


        break;


    case 'wx_login_my_order':
        $url = "http://ningjianshen.com/njs.php?mod=login&act=wx_login_my_order";
        $result = pe_wx($url);
        $openid =  $result->openid;
        $nickname =  $result->nickname;
        $user_img =  $result->headimgurl;

        $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
        if(!empty($wxuser)){
            if($wxuser['user_wxname']!=$nickname){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_name'=>$nickname));
            }
            if($wxuser['user_img']!=$user_img){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_img'=>$user_img));
            }
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=my_order');
        }else{

            $user = $db->pe_insert('user', array('user_wxid'=>$openid,'user_wxname'=>$nickname,'user_img'=>$user_img,'user_join_time'=>time()));
            $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=my_order');
        }

        break;


    case 'wx_login_open':
        $url = "http://ningjianshen.com/njs.php?mod=login&act=wx_login_open";
        $result = pe_wx($url);
        $openid =  $result->openid;
        $nickname =  $result->nickname;
        $user_img =  $result->headimgurl;

        $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
        if(!empty($wxuser)){
            if($wxuser['user_wxname']!=$nickname){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_name'=>$nickname));
            }
            if($wxuser['user_img']!=$user_img){
                $db->pe_update('user', array('user_wxid'=>$openid), array('user_img'=>$user_img));
            }
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=pay&act=open');
        }else{

            $user = $db->pe_insert('user', array('user_wxid'=>$openid,'user_wxname'=>$nickname,'user_img'=>$user_img,'user_join_time'=>time()));
            $wxuser = $db->pe_select('user',array('user_wxid'=>$openid));
            $_SESSION['user_id'] = $wxuser['user_id'];
            $_SESSION['user_isvip'] = $wxuser['user_isvip'];
            $_SESSION['user_money'] = $wxuser['user_money'];
            $_SESSION['user_name'] = $nickname;
            $_SESSION['user_img'] = $user_img;

            pe_goto('njs.php?mod=pay&act=open');
        }

        break;


    default:
        # code...
        break;
}







?>